package com.songhq.data.bean;


import java.io.Serializable;

/**
 * @Author: xuxl
 * @Date: 2019/3/19 0019 15:24
 * @Version
 */
public class Response implements Serializable {

    private static final long serialVersionUID = 1L;

    private int code;
    private String message;
    private Object body;
    private long timeStamp;

    public static Response ok() {
        Response r = new Response();
        r.setCode(200);
        r.setMessage("SUCCESS");
        r.setTimeStamp(System.currentTimeMillis());
        return r;
    }

    public static Response ok(Object body) {
        Response r = new Response();
        r.setCode(200);
        r.setMessage("SUCCESS");
        r.setBody(body);
        r.setTimeStamp(System.currentTimeMillis());
        return r;
    }

    public static Response displayOk(Object body) {
        Response r = new Response();
        r.setCode(200);
        r.setMessage("ok");
        r.setBody(body);
        r.setTimeStamp(System.currentTimeMillis());
        return r;
    }

    public static Response error(int code, String message) {
        Response r = new Response();
        r.setCode(code);
        r.setMessage(message);
        r.setTimeStamp(System.currentTimeMillis());
        return r;
    }

    public static Response contentOk(Object body) {
        Response r = new Response();
        r.setCode(200);
        r.setBody(body);
        r.setTimeStamp(System.currentTimeMillis());
        return r;
    }

    /**
     * 服务请求成功
     *
     * @param code    响应状态码
     * @param message 响应提示信息
     * @param data    响应消息体
     * @return
     */
    public static Response response(int code, String message, Object data) {
        Response r = new Response();
        r.setCode(code);
        r.setMessage(message);
        r.setBody(data);
        r.setTimeStamp(System.currentTimeMillis());
        return r;
    }

    /**
     * 服务异常
     *
     * @param code    响应状态码
     * @param message 响应提示信息
     * @param data    响应消息体
     * @return
     */
    public static Response exception(int code, String message, Object data) {
        Response r = new Response();
        r.setCode(code);
        r.setBody(data);
        r.setMessage(message);
        r.setTimeStamp(System.currentTimeMillis());
        return r;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getBody() {
        return body;
    }

    public void setBody(Object body) {
        this.body = body;
    }

    public long getTimeStamp() {
        return timeStamp;
    }

    public void setTimeStamp(long timeStamp) {
        this.timeStamp = timeStamp;
    }

}
